package com.tutu.controller.backend;

import com.tutu.common.DataTableFactory;
import com.tutu.controller.common.CommonController;
import com.tutu.service.StatisticService;
import com.tutu.utils.DateUtils;
import com.tutu.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 统计分析
 */
@Controller
@RequestMapping(value = "backend/statistic")
public class StatisticController extends CommonController {

    @Autowired
    StatisticService statisticService;

    @RequestMapping(value = "/index")
    public String index(Model model) {
        model.addAttribute("startTime", DateUtils.getDateWithDay(0, 0));
        model.addAttribute("endTime", DateUtils.getDateWithDay(0, 1));
        return "backend/statistic/list";
    }

    @RequestMapping("/list")
    public void list(HttpServletResponse response, Integer companyId, String deviceCode, Integer type, String keyWord, String startTime, String endTime, Integer draw) {
        try {
            Map<String, Object> result = DataTableFactory.fitting(draw, statisticService.findListByParams(companyId, deviceCode, type, keyWord, startTime, endTime));

            WebUtil.printJson(response, result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}